//
//  HDMuseumIntrodeceVC.m
//  HDWuDaDaoServiceCenter
//
//  Created by HDNiuKuiming on 2017/4/10.
//  Copyright © 2017年 HDNiuKuiming. All rights reserved.
//


@interface HDMuseumInfoObj : NSObject
/*
 datetime = 1492142352;
 "html_path" = "http://47.93.81.30/wdd/resource/museum/0001/CHINESE/0001.html";
 imgs =         (
 "http://47.93.81.30/wdd/resource/museum/0001/images/0001.png"
 );
 "is_can_scan" = 1;
 "museum_id" = 0001;
 "show_exhibits" = 1;
 title = "\U4e94\U5927\U9053\U535a\U7269\U9986";
 */
@property (nonatomic, copy) NSString *datetime;
@property (nonatomic, copy) NSString *html_path;
@property (nonatomic, copy) NSArray *imgs;
@property (nonatomic, copy) NSNumber *is_can_scan;
@property (nonatomic, copy) NSString *museum_id;
@property (nonatomic, copy) NSNumber *show_exhibits;
@property (nonatomic, copy) NSString *title;
//@property (nonatomic, assign, getter = isVip) BOOL vip; // getter接口

+ (instancetype)musuemWithDict:(NSDictionary *)dict;

@end

@implementation HDMuseumInfoObj


+ (instancetype)musuemWithDict:(NSDictionary *)dict
{
    return [[self alloc] initWithDict:dict];
}
- (instancetype)initWithDict:(NSDictionary *)dict
{
    if (self = [super init]) {
        [self setValuesForKeysWithDictionary:dict]; // 字典的快速赋值，需要特殊处理一下保留字段和未声明但是字典中有的字段
        
    }
    return self;
}

-(void)setValue:(id)value forUndefinedKey:(NSString *)key{
    if([key isEqualToString:@"id"]) {
    }
    if([key isEqualToString:@"username"]) {
    }
}

@end

#import "HDMapVC.h"
#import "HDMuseumIntrodeceVC.h"

@interface HDMuseumIntrodeceVC ()
@property (weak, nonatomic) IBOutlet UIWebView *myWebView;
@property (weak, nonatomic) IBOutlet UIButton *listenBtn;
@property (nonatomic, strong) HDMuseumInfoObj *museumObj;

@end

@implementation HDMuseumIntrodeceVC

#pragma mark
#pragma mark -------- Init Methods --------

- (void)viewDidLoad {
    [super viewDidLoad];
    [self requestInfoAction];
}

- (void)requestInfoAction
{
    NSString *museumID = _requestDic[@"id"];
    if (museumID.length == 0)
        return;
    
    HDRequestObj *loginObj = [[HDRequestObj alloc] init];
    NSString *urlPath = [NSString stringWithFormat:@"%@g=mapi&m=Contentinfo&a=museum_detail", HTTP_Request_URL_Prefix];
    NSDictionary *parameters = @{@"device_id": [[HDDeclare sharedDeclare] userPhoneID],
                                 @"language": @"CHINESE",
                                 @"museum_id":museumID};
    
    [loginObj requestGetPath:urlPath Parameter:parameters withVC:self timeout:5];
    loginObj.myDataBlock = ^(NSDictionary *dataDic){
        
        NSString *loginCode = dataDic[@"status"];
        if (loginCode.integerValue == 1) {
            NSDictionary *objDic = dataDic[@"data"];
            _museumObj = [HDMuseumInfoObj musuemWithDict:objDic];
            _nameLabel.text = _museumObj.title;
            [self reloadViewAction];
            [[HDDeclare sharedDeclare] setNowMuseumID:_museumObj.museum_id];
        }
        else {
        }
    };
}

- (void)reloadViewAction
{
    if (_museumObj != nil) {
        NSString *webPath = _museumObj.html_path;
        NSURL *myURL = [NSURL URLWithString:webPath];
        [_myWebView loadRequest:[NSURLRequest requestWithURL:myURL]];

        
        if (_museumObj.show_exhibits.integerValue == 1) {
            _listenBtn.hidden = NO;
            [_listenBtn setTitle:@"扫条码，听讲解" forState:UIControlStateNormal];
            
            if (_museumObj.is_can_scan != nil && _museumObj.is_can_scan.integerValue == 0){
                [_listenBtn setTitle:@"收听讲解" forState:UIControlStateNormal];
            }
        }
        
        else {
            _listenBtn.hidden = YES;
        }
    }
}

- (IBAction)pushToQRpageOrMapAction:(id)sender {
    
    if([[HDDeclare sharedDeclare] userPhoneID].length < 8)
    {
        [[HDDeclare sharedDeclare] userIDRequestAction];
        return;
    }
    
    // 跳到地图
    if (_museumObj.is_can_scan != nil &&_museumObj.is_can_scan.integerValue == 0) {
        
        [self performSegueWithIdentifier:@"introducePagePushToMap" sender:nil];
    }
    // 跳到扫码
    else {
        [self performSegueWithIdentifier:@"IntroducePagePushToQRCodeLine" sender:nil];
    }
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"introducePagePushToMap"]) {
        HDMapVC *VC = segue.destinationViewController;
        VC.museumID = _museumObj.museum_id;
    }
    else if ([segue.identifier isEqualToString:@"IntroducePagePushToQRCodeLine"]) {

    }
}

#pragma mark
#pragma mark -------- Dealloc Methods -------

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (IBAction)backAction:(id)sender {
    [super back];
}

@end
